package com.fourth_groups.shopping121store.ui.cart.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fourth_groups.shopping121store.R;
import com.fourth_groups.shopping121store.bean.GoodsDetailBean;

import java.util.List;

/**
 * Created by Administrator on 2016/10/12.
 */

public class CartListViewAdapter extends BaseAdapter {
    static List<GoodsDetailBean> myGoodsDetailsList;

    public void setData(List<GoodsDetailBean> goodsDetails){//设置数据
        this.myGoodsDetailsList=goodsDetails;
    }

    public CartListViewAdapter() {}

    @Override
    public int getCount() {
        return myGoodsDetailsList!=null?myGoodsDetailsList.size():0;
    }

    @Override
    public Object getItem(int position) {
        return myGoodsDetailsList!=null?myGoodsDetailsList.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_cart, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //绑定数据
//        String storeImage = mListBeans.get(position).getImg();
//        String commodityImage = mListBeans.get(position).getImg();

//        String storeName = mListBeans.get(position).getName();
//        String commodityName = mListBeans.get(position).getUpdateTime();
//        String commodityRebate1Amount = mListBeans.get(position).getLenght();
//        String commodityPrice = mListBeans.get(position).getLenght();


//        //使用glide下载图片
//        Glide.with(parent.getContext()).load(storeImage).into(holder.storeImage);
//        Glide.with(parent.getContext()).load(commodityImage).into(holder.commodityImage);

//        holder.storeName.setText(storeName);
//        holder.commodityName.setText(commodityName);
//        holder.commodityRebate1Amount.setText(commodityRebate1Amount);
//        holder.commodityPrice.setText(commodityPrice);

        return convertView;
    }

    static class ViewHolder{
        private  ImageView storeImage,commodityImage;
        private  TextView  storeName, commodityName, commodityRebate1Amount,commodityPrice;

        public ViewHolder(View contentView) {
            storeImage = (ImageView) contentView.findViewById(R.id.iv_store_image_cart);
            storeName = (TextView) contentView.findViewById(R.id.tv_store_name_cart);

            commodityImage = (ImageView) contentView.findViewById(R.id.iv_commodity_image_cart);
            commodityName = (TextView) contentView.findViewById(R.id.tv_commodity_name_cart);
            commodityPrice = (TextView) contentView.findViewById(R.id.tv_commodity_price_cart);
            commodityRebate1Amount = (TextView) contentView.findViewById(R.id.tv_commodity_rebate1_amount_cart);

        }
    }

}
